//财务管理-1对账汇总-汇总管理
import '../Finance.css'
import http from '../../../utils/http';
import { useEffect } from 'react';
import { NavLink , useSearchParams } from 'react-router-dom'
import { Table , Button } from '@arco-design/web-react';
const columns1 = [{
  title: '对账批次号',
  dataIndex: 'id',
  key:'id'
},
{
  title: '交易时间',
  dataIndex: 'time',
  key:'time'
},
{
  title: '对账类型',
  dataIndex: 'type1',
  key:'type1'
},
{
  title: '交易类型',
  dataIndex: 'type2',
  key:'type2'
},
{
  title: '对账笔数',
  key:'ledger_num',
  render: (_, record) => (
    <span>
      <div>{record.ledger_num[0]}</div>
      <div>{record.ledger_num[1]}</div>
    </span>
  )
},
{
  title: '对账金额',
  key:'ledger_money',
  render: (_, record) => (
    <span>
      <div>{record.ledger_money[0]}</div>
      <div>{record.ledger_money[1]}</div>
    </span>
  )
},
{
  title: '对账差错',
  key:'ledger_diff',
  render: (_, record) => (
    <span>
      <div>{record.ledger_diff[0]}</div>
      <div>{record.ledger_diff[1]}</div>
    </span>
  )
}];
const data1 = [{
  id: 'DZ20394727',
  time: '2019-12-01',
  type1: '支付宝',
  type2: '消费',
  ledger_num:['支付宝 195笔','商户AA 194笔'],
  ledger_money:['支付宝 3985元','商户AA 3925元'],
  ledger_diff:['支付宝 1笔 60元','商户AA 0笔 0元'],
}];
var arrData2=['已对平','自动核销','存疑账-单边','差错账-单边','差错账-金额不符']
var afterNum=-1
const columns2 =[{
  title: '',
  key:'',
  render: (_, record) => {
      afterNum++
      return arrData2[afterNum]
  }
},{
  title: '支付宝对账总笔数',
  dataIndex: 'total1',
  key:'total1'
},
{
  title: '支付宝对账总金额',
  dataIndex: 'money1',
  key:'money1'
},
{
  title: '商户AA对账总笔数',
  dataIndex: 'total2',
  key:'total2'
},
{
  title: '商户AA对账总金额',
  dataIndex: 'money2',
  key:'money2'
},
{
  title: '处理',
  key:'state',
  render: (_, record) => {
    if(afterNum===5){
      return <span></span>
    }else{
      if(record.state){
        return <NavLink to='/home/finance/result'><Button type='text'>查看结果</Button></NavLink>
      } else {
        return <NavLink to='/home/finance/handle'><Button type='text'>立即处理</Button></NavLink>
      }
    }
  }
}]
const data2 = [{
  total1:1110,
  money1:55000,
  total2:1100,
  money2:56800,
  state:1
},{
  total1:7,
  money1:350,
  total2:5,
  money2:250,
  state:0
},{
  total1:15,
  money1:750,
  total2:10,
  money2:500,
  state:1
},{
  total1:4,
  money1:200,
  total2:10,
  money2:500,
  state:1
},{
  total1:1,
  money1:50,
  total2:1,
  money2:50,
  state:1,
  key:5
}];
//表格数据综合计算
function sum(currentData) {
  return (
    <Table.Summary.Row className='sum'>
      <Table.Summary.Cell>总计</Table.Summary.Cell>
      <Table.Summary.Cell >
        {currentData.reduce((prev, next) => prev + next.total1, 0)}
      </Table.Summary.Cell>
      <Table.Summary.Cell>
        {currentData.reduce((prev, next) => prev + next.money1, 0)}
      </Table.Summary.Cell>
      <Table.Summary.Cell>
        {currentData.reduce((prev, next) => prev + next.total2, 0)}
      </Table.Summary.Cell>
      <Table.Summary.Cell>
        {currentData.reduce((prev, next) => prev + next.money2, 0)}
      </Table.Summary.Cell>
      <Table.Summary.Cell/>
    </Table.Summary.Row>
  );
}
const Single = () => {
  const [search,setSearch]=useSearchParams();
  console.log(search.get('batchNumber'),'跳转获取值');

  useEffect(()=>{
    console.log('useEfect触发');
    link()
  },[])
  const link = () => {
    http({
      url: '/reconciliationDes',
      method: 'post',
    }).then((res) => {
      console.log(res);
      // succLink(res.result.data)
    })
  }
  const succLink=(v)=>{
    
  }
  return (
    <div className='bigBox'>
      <div className='title'>
        <div>
          <span>财务管理</span>
          <span>  /  </span>
          <span>对账汇总</span>
          <span>  /  </span>
          <span className='bold'>汇总详情</span>
        </div>
        <h2>汇总详情</h2>
      </div>
      <div className='content'>
        <div className='c_msg'>
          <Table columns={columns1} data={data1} pagination={false}/>
        </div>
        <div className='c_table c_table2'>
          <Table columns={columns2} data={data2} pagination={false} rowKey='key' summary={sum}/>
          <NavLink to='/home/finance/total'><Button type='outline' status='warning'>返回</Button></NavLink>
        </div>
      </div>
    </div>
  )
}
export default Single
